home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Libraries / tcl7.4b3 / doc / SetVar.3 < prev    next >
Encoding:
Text File  |  1995-02-01  |  5.8 KB  |  159 lines

  1. '\"
  2. '\" Copyright (c) 1989-1993 The Regents of the University of California.
  3. '\" Copyright (c) 1994 Sun Microsystems, Inc.
  4. '\"
  5. '\" See the file "license.terms" for information on usage and redistribution
  6. '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  7. '\" 
  8. '\" @(#) SetVar.3 1.18 95/02/01 14:30:27
  9. '\" 
  10. .so man.macros
  11. .HS Tcl_SetVar tclc 7.4
  12. .BS
  13. .SH NAME
  14. Tcl_SetVar, Tcl_SetVar2, Tcl_GetVar, Tcl_GetVar2, Tcl_UnsetVar, Tcl_UnsetVar2 \- manipulate Tcl variables
  15. .SH SYNOPSIS
  16. .nf
  17. \fB#include <tcl.h>\fR
  18. .sp
  19. char *
  20. \fBTcl_SetVar\fR(\fIinterp, varName, newValue, flags\fR)
  21. .sp
  22. char *
  23. \fBTcl_SetVar2\fR(\fIinterp, name1, name2, newValue, flags\fR)
  24. .sp
  25. char *
  26. \fBTcl_GetVar\fR(\fIinterp, varName, flags\fR)
  27. .sp
  28. char *
  29. \fBTcl_GetVar2\fR(\fIinterp, name1, name2, flags\fR)
  30. .sp
  31. int
  32. \fBTcl_UnsetVar\fR(\fIinterp, varName, flags\fR)
  33. .sp
  34. int
  35. \fBTcl_UnsetVar2\fR(\fIinterp, name1, name2, flags\fR)
  36. .SH ARGUMENTS
  37. .AS Tcl_Interp *newValue
  38. .AP Tcl_Interp *interp in
  39. Interpreter containing variable.
  40. .AP char *varName in
  41. Name of variable.  May refer to a scalar variable or an element of
  42. an array variable.
  43. .VS
  44. If the name references an element of an array, then it
  45. must be in writable memory:  Tcl will make temporary modifications 
  46. to it while looking up the name.
  47. .VE
  48. .AP char *newValue in
  49. New value for variable.
  50. .AP int flags in
  51. OR-ed combination of bits providing additional information for
  52. operation. See below for valid values.
  53. .AP char *name1 in
  54. Name of scalar variable, or name of array variable if \fIname2\fR
  55. is non-NULL.
  56. .AP char *name2 in
  57. If non-NULL, gives name of element within array and \fIname1\fR
  58. must refer to an array variable.
  59. .BE
  60.  
  61. .SH DESCRIPTION
  62. .PP
  63. These procedures may be used to create, modify, read, and delete
  64. Tcl variables from C code.
  65. \fBTcl_SetVar\fR and \fBTcl_SetVar2\fR will create a new variable
  66. or modify an existing one.
  67. Both of these procedures set the given variable to the value
  68. given by \fInewValue\fR, and they return a pointer to a
  69. copy of the variable's new value, which is stored in Tcl's
  70. variable structure.
  71. Tcl keeps a private copy of the variable's value, so the caller
  72. may change \fInewValue\fR after these procedures return without
  73. affecting the value of the variable.
  74. If an error occurs in setting the variable (e.g. an array
  75. variable is referenced without giving an index into the array),
  76. then NULL is returned.
  77. .PP
  78. The name of the variable may be specified in either of two ways.
  79. If \fBTcl_SetVar\fR is called, the variable name is given as
  80. a single string, \fIvarName\fR.
  81. If \fIvarName\fR contains an open parenthesis and ends with a
  82. close parenthesis, then the value between the parentheses is
  83. treated as an index (which can have any string value) and
  84. the characters before the first open
  85. parenthesis are treated as the name of an array variable.
  86. If \fIvarName\fR doesn't have parentheses as described above, then
  87. the entire string is treated as the name of a scalar variable.
  88. If \fBTcl_SetVar2\fR is called, then the array name and index
  89. have been separated by the caller into two separate strings,
  90. \fIname1\fR and \fIname2\fR respectively;  if \fIname2\fR is
  91. zero it means that a scalar variable is being referenced.
  92. .PP
  93. The \fIflags\fR argument may be used to specify any of several
  94. options to the procedures.
  95. It consists of an OR-ed combination of any of the following
  96. bits:
  97. .IP TCL_GLOBAL_ONLY
  98. Under normal circumstances the procedures look up variables
  99. at the current level of procedure call for \fIinterp\fR, or
  100. at global level if there is no call active.
  101. However, if this bit is set in \fIflags\fR then the variable
  102. is looked up at global level even if there is a procedure
  103. call active.
  104. .IP TCL_LEAVE_ERR_MSG
  105. If an error is returned and this bit is set in \fIflags\fR, then
  106. an error message will be left in \fI\%interp->result\fR.  If this
  107. flag bit isn't set then no error message is left (\fI\%interp->result\fR
  108. will not be modified).
  109. .IP TCL_APPEND_VALUE
  110. If this bit is set then \fInewValue\fR is appended to the current
  111. value, instead of replacing it.
  112. If the variable is currently undefined, then this bit is ignored.
  113. .IP TCL_LIST_ELEMENT
  114. If this bit is set, then \fInewValue\fR is converted to a valid
  115. Tcl list element before setting (or appending to) the variable.
  116. A separator space is appended before the new list element unless
  117. .VS
  118. the list element is going to be the first element in a list or
  119. sublist (i.e. the variable's current value is empty, or contains
  120. the single character ``{'', or ends in `` }'').
  121. .VE
  122. .PP
  123. \fBTcl_GetVar\fR and \fBTcl_GetVar2\fR return the current value
  124. of a variable.
  125. The arguments to these procedures are treated in the same way
  126. as the arguments to \fBTcl_SetVar\fR and \fBTcl_SetVar2\fR.
  127. Under normal circumstances, the return value is a pointer
  128. to the variable's value (which is stored in Tcl's variable
  129. structure and will not change before the next call to \fBTcl_SetVar\fR
  130. or \fBTcl_SetVar2\fR).
  131. The only bits of \fIflags\fR that are used are TCL_GLOBAL_ONLY
  132. and TCL_LEAVE_ERR_MSG, both of
  133. which have
  134. the same meaning as for \fBTcl_SetVar\fR.
  135. If an error occurs in reading the variable (e.g. the variable
  136. doesn't exist or an array element is specified for a scalar
  137. variable), then NULL is returned.
  138. .PP
  139. \fBTcl_UnsetVar\fR and \fBTcl_UnsetVar2\fR may be used to remove
  140. a variable, so that future calls to \fBTcl_GetVar\fR or \fBTcl_GetVar2\fR
  141. for the variable will return an error.
  142. The arguments to these procedures are treated in the same way
  143. as the arguments to \fBTcl_GetVar\fR and \fBTcl_GetVar2\fR.
  144. .VS
  145. If the variable is successfully removed then TCL_OK is returned.
  146. If the variable cannot be removed because it doesn't exist then
  147. TCL_ERROR is returned.
  148. .VE
  149. If an array element is specified, the given element is removed
  150. but the array remains.
  151. If an array name is specified without an index, then the entire
  152. array is removed.
  153.  
  154. .SH "SEE ALSO"
  155. Tcl_TraceVar
  156.  
  157. .SH KEYWORDS
  158. array, interpreter, scalar, set, unset, variable
  159.